package com.zy.mc_module.view;

import android.content.Context;
import android.util.AttributeSet;

/**
 * Created on 19/1/12
 */
public class CheckedImageView extends androidx.appcompat.widget.AppCompatImageView {

    private boolean isChecked = false;//img的选中状态
    private int color;

    public CheckedImageView(Context context) {
        super(context);
    }

    public CheckedImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setImageRes(int resId, boolean checked) {
        this.setImageResource(resId);
        isChecked = checked;
        if (isChecked) {
            clearColorFilter();
        } else {
            setColorFilter(color);
        }
    }

    public boolean getChecked() {
        return isChecked;
    }

    public void setColorFilters(int color) {
        this.color = color;
        if (isChecked) {
            clearColorFilter();
        } else {
            setColorFilter(color);
        }
    }
}
